package com.lmt.api;

import com.lmt.base.ResultData;
import com.lmt.entity.CollectionFolder;
import com.lmt.entity.search.CollectionFolderSearch;
import com.lmt.service.CollectionFolderService;
import com.lmt.util.RedisCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Date 2018/07/17
 *
 * @author MT-Lin
 */
@RestController
@RequestMapping("/CollectionFolderApi")
public class CollectionFolderApi {

	private final CollectionFolderService collectionFolderService;

	private final RedisCacheUtil redisCacheUtil;

	@Autowired
	public CollectionFolderApi(CollectionFolderService collectionFolderService, RedisCacheUtil redisCacheUtil) {
		this.collectionFolderService = collectionFolderService;
		this.redisCacheUtil = redisCacheUtil;
	}

	@RequestMapping("/save")
	public ResultData save(@RequestBody CollectionFolder collectionFolder) {
		collectionFolder.setCreator(redisCacheUtil.getUserId(collectionFolder));
		return this.collectionFolderService.save(collectionFolder);
	}

	@RequestMapping("/search")
	public ResultData search(@RequestBody CollectionFolderSearch collectionFolderSearch) {
		return this.collectionFolderService.search(collectionFolderSearch);
	}

	@RequestMapping("/getParentTree")
	public ResultData getParentTree() {
		return this.collectionFolderService.getParentTree();
	}

	@RequestMapping("/delete")
	public ResultData delete(@RequestBody List<CollectionFolder> collectionFolders) {
		return this.collectionFolderService.delete(collectionFolders);
	}

	@RequestMapping("/update")
	public ResultData update(@RequestBody CollectionFolder collectionFolder) {
		return this.collectionFolderService.update(collectionFolder);
	}
}
